﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Office.Interop.Excel;
using System.Drawing;
using System.IO;

public partial class Admin_panel_ThongKe_frmThongKe_PhuLuc_01 : System.Web.UI.Page
{
    public int _nam = 0;
    public BieumauDataContext _db = new BieumauDataContext();
    tblCauHinhThongKe tk = null;

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Request.QueryString["nam"] == null)
                Response.Redirect("TimKiem.aspx");
            lblNam.Text = Request.QueryString["nam"];
            tk = _db.tblCauHinhThongKes.Single(p => p.ID == "001");
            _nam = Convert.ToInt32(Request.QueryString["nam"]);

          
            lblDonViBaoCao.Text = tk.DonViGui;
            lblDonViNhan.Text = tk.DonViNhan;
            txtGiamDoc.Text = tk.GiamDoc;
            txtNguoiLapBieu.Text = tk.NguoiLapBieu;
            txtDiaDiemKy.Text = tk.NoiGui;
            txtNgayKy.Text = DateTime.Now.Day.ToString();
            txtThangKy.Text = DateTime.Now.Month.ToString();
            txtNamKy.Text = DateTime.Now.Year.ToString();

            txtNgayKy.BackColor = System.Drawing.Color.FromArgb(255, 255, 255);
            txtThangKy.BackColor = System.Drawing.Color.FromArgb(255, 255, 255);
            txtNamKy.BackColor = System.Drawing.Color.FromArgb(255, 255, 255);
           // string path = Server.MapPath("~/userfiles/vanban/ThongKe_PhuLuc_1.xls");
           // Export_To_File(path);
        }
        catch (Exception ex)
        {
            //Response.Redirect("../TimKiem.aspx");
           // throw;
        }

    }

    //private void Export_To_File(string fileName)
    //{
        
    //    try
    //    {

    //        // load dữ liệu 
    //        tblCauHinhThongKe tk = _db.tblCauHinhThongKes.Single(p => p.ID == "001");

    //        //
    //        Microsoft.Office.Interop.Excel.Application xlApp;
    //        Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
    //        Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;
    //        object misValue = System.Reflection.Missing.Value;

    //        xlApp = new Microsoft.Office.Interop.Excel.Application();
    //        xlWorkBook = xlApp.Workbooks.Add(misValue);
    //        xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
    //        xlWorkSheet.Name = "Thong Ke - Phu Luc 1";




    //        //add data




    //        xlWorkSheet.Cells[1, 1] = "Phụ lục I";
    //        xlWorkSheet.get_Range("A1:F1",Type.Missing).Merge(Type.Missing);

    //        xlWorkSheet.Cells[2, 1] = "THÔNG TIN CHUNG VỀ  CÁC ĐƠN VỊ BÁO CÁO";
    //        xlWorkSheet.get_Range("A2:F2", Type.Missing).Merge(Type.Missing);

    //        xlWorkSheet.Cells[3, 1] = "(Ban hành kèm theo Thông tư số 05/2010/TT-BKHCN ngày 02 tháng  07  năm 2010 của  Bộ trưởng Bộ Khoa học và Công nghệ)";
    //        xlWorkSheet.get_Range("A3:F3", Type.Missing).Merge(Type.Missing);

    //        xlWorkSheet.Cells[4, 1] = "--------------------------------------------------------";
    //        xlWorkSheet.get_Range("A4:F4", Type.Missing).Merge(Type.Missing);

    //        xlWorkSheet.Cells[5, 1] = "Biểu 01CS-KHCN";
    //        xlWorkSheet.get_Range("A5:F5", Type.Missing).Merge(Type.Missing);

    //        xlWorkSheet.Cells[7, 1] = "THÔNG TIN CHUNG VỀ  CÁC ĐƠN VỊ BÁO CÁO";
    //        xlWorkSheet.get_Range("A7:F7", Type.Missing).Merge(Type.Missing);

    //        xlWorkSheet.Cells[8, 1] = "(Tính đến ngày 31/12 năm "+_nam+" )";
    //        xlWorkSheet.get_Range("A8:F8", Type.Missing).Merge(Type.Missing);

    //        xlWorkSheet.Cells[10, 1] = "Ngày gửi báo cáo: .........................";
    //        xlWorkSheet.Cells[10, 5] = "Đơn vị báo cáo: "+tk.DonViGui ;

    //        xlWorkSheet.Cells[11, 1] = "(trước 28/02 theo dấu bưu điện)";
    //        xlWorkSheet.Cells[11, 5] = "Đơn vị nhận báo cáo: "+tk.DonViNhan ;

    //        // hàng tiêu đề cột
    //        xlWorkSheet.Cells[13, 1] = "STT";
    //        ((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[13, 1]).EntireColumn.ColumnWidth = 5;
    //        xlWorkSheet.get_Range("A13:A14", Type.Missing).Merge(Type.Missing);

    //        xlWorkSheet.Cells[13, 2] = "Tên đơn vị báo cáo";
    //        ((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[13, 2]).EntireColumn.ColumnWidth = 25;
    //        xlWorkSheet.get_Range("B13:B14", Type.Missing).Merge(Type.Missing);

    //        xlWorkSheet.Cells[13, 3] = "Tên giao dịch viết tắt";
    //        ((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[13, 3]).EntireColumn.ColumnWidth = 20;
    //        xlWorkSheet.get_Range("C13:C14", Type.Missing).Merge(Type.Missing);

    //        xlWorkSheet.Cells[13, 4] = "Tên Tiếng anh (nếu có)";
    //        ((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[13, 4]).EntireColumn.ColumnWidth = 20;
    //        xlWorkSheet.get_Range("D13:D14", Type.Missing).Merge(Type.Missing);

    //        xlWorkSheet.Cells[13, 5] = "Địa chỉ";
    //        ((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[13, 5]).EntireColumn.ColumnWidth = 25;
    //        xlWorkSheet.get_Range("E13:E14", Type.Missing).Merge(Type.Missing);

    //        xlWorkSheet.Cells[13, 6] = "Điện thoại";
    //        ((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[13, 6]).EntireColumn.ColumnWidth = 15;
    //        xlWorkSheet.get_Range("F13:F14", Type.Missing).Merge(Type.Missing);

    //        xlWorkSheet.Cells[13, 7] = "Fax";
    //        ((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[13, 7]).EntireColumn.ColumnWidth = 15;
    //        xlWorkSheet.get_Range("G13:G14", Type.Missing).Merge(Type.Missing);

    //        xlWorkSheet.Cells[13, 8] = "Email";
    //        ((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[13, 8]).EntireColumn.ColumnWidth = 15;
    //        xlWorkSheet.get_Range("H13:H14", Type.Missing).Merge(Type.Missing);

    //        xlWorkSheet.Cells[13, 9] = "Website";
    //        ((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[13, 9]).EntireColumn.ColumnWidth = 15;
    //        xlWorkSheet.get_Range("I13:I14", Type.Missing).Merge(Type.Missing);

    //        // 
    //        xlWorkSheet.Cells[13, 10] = "Số quyết định thành lập";
    //        ((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[13, 10]).EntireColumn.ColumnWidth = 25;
    //        xlWorkSheet.get_Range("J13:J14", Type.Missing).Merge(Type.Missing);

    //        xlWorkSheet.Cells[13, 11] = "Ngày thành lập";
    //        ((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[13, 11]).EntireColumn.ColumnWidth = 15;
    //        xlWorkSheet.get_Range("K13:K14", Type.Missing).Merge(Type.Missing);

    //        xlWorkSheet.Cells[13, 12] = "Mã số thuế";
    //        ((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[13, 12]).EntireColumn.ColumnWidth = 25;
    //        xlWorkSheet.get_Range("L13:L14", Type.Missing).Merge(Type.Missing);

    //        xlWorkSheet.Cells[13, 13] = "Giấy chứng nhận đăng ký hoạt động KH&CN số";
    //        ((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[13, 13]).EntireColumn.ColumnWidth = 25;
    //        xlWorkSheet.get_Range("M13:M14", Type.Missing).Merge(Type.Missing);

    //        xlWorkSheet.Cells[13, 14] = "Ngày cấp";
    //        ((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[13, 14]).EntireColumn.ColumnWidth = 15;
    //        xlWorkSheet.get_Range("N13:N14", Type.Missing).Merge(Type.Missing);

    //        xlWorkSheet.Cells[13, 15] = "Nơi cấp";
    //        ((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[13, 15]).EntireColumn.ColumnWidth = 25;
    //        xlWorkSheet.get_Range("O13:O14", Type.Missing).Merge(Type.Missing);

    //        xlWorkSheet.Cells[13, 16] = "Cấp quyết định thành lập";
    //        ((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[13, 16]).EntireColumn.ColumnWidth = 25;
    //        xlWorkSheet.get_Range("P13:P14", Type.Missing).Merge(Type.Missing);

    //        xlWorkSheet.Cells[13, 17] = "Cơ quan quản lý trực tiếp";
    //        ((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[13, 17]).EntireColumn.ColumnWidth = 25;
    //        xlWorkSheet.get_Range("Q13:Q14", Type.Missing).Merge(Type.Missing);

    //        xlWorkSheet.Cells[13, 18] = "Bộ/ngành, tỉnh/thành phố trực thuộc Trung ương chủ quản";
    //        ((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[13, 18]).EntireColumn.ColumnWidth = 25;
    //        xlWorkSheet.get_Range("R13:R14", Type.Missing).Merge(Type.Missing);
            
    //        xlWorkSheet.Cells[13,19] = "Loại hình của đơn vị/tổ chức";
    //        ((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[13, 19]).EntireColumn.ColumnWidth = 25;
    //        xlWorkSheet.get_Range("S13:S14", Type.Missing).Merge(Type.Missing);

    //        xlWorkSheet.Cells[13, 20] = "Thành phần kinh tế";
    //        ((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[13, 20]).EntireColumn.ColumnWidth = 25;
    //        xlWorkSheet.get_Range("T13:T14", Type.Missing).Merge(Type.Missing);

    //        xlWorkSheet.Cells[13,21] = "Tổng giá trị tài sản cố định (triệu đồng)";
    //        ((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[13, 21]).EntireColumn.ColumnWidth = 20;
    //        xlWorkSheet.get_Range("U13:U14", Type.Missing).Merge(Type.Missing);

    //        xlWorkSheet.Cells[13, 22] = "Tổng giá trị vốn lưu động (triệu đồng)";
    //        ((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[13, 22]).EntireColumn.ColumnWidth = 20;
    //        xlWorkSheet.get_Range("V13:V14", Type.Missing).Merge(Type.Missing);

    //        xlWorkSheet.Cells[13, 23] = "Các đơn vị trực thuộc ";
    //        xlWorkSheet.get_Range("w13:Z13", Type.Missing).Merge(Type.Missing);

    //        xlWorkSheet.Cells[14, 23] = "STT";
    //        ((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[14, 23]).EntireColumn.ColumnWidth = 5;

    //        xlWorkSheet.Cells[14, 24] = "Tên đơn vị";
    //        ((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[14, 24]).EntireColumn.ColumnWidth = 30;

    //        xlWorkSheet.Cells[14, 25] = "Họ và tên thủ trưởng";
    //        ((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[14, 25]).EntireColumn.ColumnWidth = 25;

    //        xlWorkSheet.Cells[14, 26] = "Địa chỉ, điện thoại, fax, email";
    //        ((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[14, 26]).EntireColumn.ColumnWidth = 30;

    //        // canh giữa , bôi đen
    //        xlWorkSheet.get_Range("A1:F9",Type.Missing).HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
    //        xlWorkSheet.get_Range("A1:F9", Type.Missing).Font.Bold = true;
    //        xlWorkSheet.get_Range("A5:F5", Type.Missing).HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignRight;
    //        xlWorkSheet.get_Range("A13:Z14", Type.Missing).HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
    //        xlWorkSheet.get_Range("A13:Z14", Type.Missing).VerticalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
    //        xlWorkSheet.get_Range("A13:Z14", Type.Missing).Font.Bold = true;
    //        xlWorkSheet.get_Range("A13:Z14", Type.Missing).WrapText = true;
            
    //        // điền dữ liệu lên file excel

    //        var _bieumau = from p in _db.tblBieuMaus
    //                      where p.NamBaoCao == Convert.ToInt32(_nam) && p.TenBieuMau.Equals("PL_01")
    //                      select p;

    //        // lùi lại 1 đơn vị để ++ cho dễ
    //        int _hang = 14, _cot = 0, _stt = 0, _hangThem = 0;
    //        string[] _arrDuLieuTach ;

    //        string _cap ="",_loai="",_thanhphan="";
            
    //        foreach (tblBieuMau bm in _bieumau)
    //        {
    //            _stt++;
    //            _hang++;
    //            _cot = 0;
    //            _arrDuLieuTach = bm.DuLieu.Split(',');
    //            _cap="";


    //             // lấy cấp :
    //            if(_arrDuLieuTach[18].Equals("True"))
    //              _cap+=" Chính phủ,";
    //            if(_arrDuLieuTach[19].Equals("True"))
    //              _cap+=" Thủ tướng Chính phủ,";
    //            if(_arrDuLieuTach[20].Equals("True"))
    //              _cap+="Bộ/ngành,";
    //            if(_arrDuLieuTach[21].Equals("True"))
    //              _cap+="Tỉnh,  Tp. trực thuộc TƯ,";
    //            if(_arrDuLieuTach[22].Equals("True"))
    //              _cap+="Cơ quan TƯ của đoàn thể,";
    //            if(_arrDuLieuTach[23].Equals("True"))
    //              _cap+="Cơ sở,";
    //            _cap = _cap.Substring(0,_cap.Length-1);

    //            // lấy loại hình
    //            if(_arrDuLieuTach[26].Equals("True"))
    //              _loai+=" Hành chính,";
    //             if(_arrDuLieuTach[27].Equals("True"))
    //              _loai+=" Đơn vị nghiên cứu và phát triển,";
    //             if(_arrDuLieuTach[28].Equals("True"))
    //              _loai+=" Trường đại học, cao đẳng, học viện,";
    //             if(_arrDuLieuTach[29].Equals("True"))
    //              _loai+=" Đơn vị dịch vụ KH&CN,";
    //             if(_arrDuLieuTach[30].Equals("True"))
    //              _loai+=" Doanh nghiệp KH&CN,";
    //             if(_arrDuLieuTach[31].Equals("True"))
    //              _loai+=" Doanh nghiệp,";
    //            _loai = _loai.Substring(0,_loai.Length-1);

    //            // lấy thành phần
    //             if(_arrDuLieuTach[32].Equals("True"))
    //              _thanhphan+=" Nhà nước,";
    //            if(_arrDuLieuTach[33].Equals("True"))
    //              _thanhphan+=" Tập thể,";
    //            if(_arrDuLieuTach[34].Equals("True"))
    //              _thanhphan+=" Tư nhân,";
    //            if(_arrDuLieuTach[35].Equals("True"))
    //              _thanhphan+=" Có vốn đầu tư nước ngoài,";
    //            _thanhphan =  _thanhphan.Substring(0, _thanhphan.Length-1   );

    //            xlWorkSheet.Cells[_hang, ++_cot] = _stt.ToString();
    //            xlWorkSheet.Cells[_hang, ++_cot] = _arrDuLieuTach[3]; // ten don vi
    //                xlWorkSheet.Cells[_hang, ++_cot] = _arrDuLieuTach[4]; // ten giao dich
    //                xlWorkSheet.Cells[_hang, ++_cot] = _arrDuLieuTach[5]; // ten tiegn Anh
    //                xlWorkSheet.Cells[_hang, ++_cot] = _arrDuLieuTach[6]+", "+ _arrDuLieuTach[7]; // dia chi, tinh TP
    //                xlWorkSheet.Cells[_hang, ++_cot] = _arrDuLieuTach[8]; // dien thoai
    //                xlWorkSheet.Cells[_hang, ++_cot] = _arrDuLieuTach[9]; // fax
    //                xlWorkSheet.Cells[_hang, ++_cot] = _arrDuLieuTach[10]; // email
    //                xlWorkSheet.Cells[_hang, ++_cot] = _arrDuLieuTach[11]; // website
    //                xlWorkSheet.Cells[_hang, ++_cot] = _arrDuLieuTach[12]; // so queyt dinh thanh lap
    //                xlWorkSheet.Cells[_hang, ++_cot] = _arrDuLieuTach[13]; // ngay thanh lap
    //                xlWorkSheet.Cells[_hang, ++_cot] = _arrDuLieuTach[14]; // ma so thue
    //                xlWorkSheet.Cells[_hang, ++_cot] = _arrDuLieuTach[15]; // so chung nhan
    //                xlWorkSheet.Cells[_hang, ++_cot] = _arrDuLieuTach[16]; // ngay chung nhan
    //                xlWorkSheet.Cells[_hang, ++_cot] = _arrDuLieuTach[17];// noi cap chung nhan
    //                xlWorkSheet.Cells[_hang, ++_cot] = _cap ; // cấp quyet dinh thành lap
    //                xlWorkSheet.Cells[_hang, ++_cot] = _arrDuLieuTach[24]; // co quan quan li truc tiep
    //                xlWorkSheet.Cells[_hang, ++_cot] =  _arrDuLieuTach[25]; // bo nganh chu quan
    //                xlWorkSheet.Cells[_hang, ++_cot] = _loai ; // loại hình 
    //                xlWorkSheet.Cells[_hang, ++_cot] = _thanhphan ; //thanh phần kinh tế
    //            xlWorkSheet.Cells[_hang, ++_cot] = !_arrDuLieuTach[36].Equals("") ? Convert.ToDecimal(_arrDuLieuTach[36]) :0 ; // tai san co dinh                   
    //            xlWorkSheet.Cells[_hang, ++_cot] =!_arrDuLieuTach[37].Equals("")? Convert.ToDecimal(_arrDuLieuTach[37]):0; // tai san luu dong
                
    //                string[] _subrow1 = _arrDuLieuTach[41].Split('-');
    //                string[] _subrow2 = _arrDuLieuTach[42].Split('-');
    //                string[] _subrow3 = _arrDuLieuTach[43].Split('-');

    //                if (_subrow1[0].Equals(""))
    //                    continue;
    //                else // tức là bảng nhỏ có dữ liệu
    //                {
    //                    if (!_subrow1[0].Equals(""))
    //                    {
    //                        xlWorkSheet.Cells[_hang, ++_cot] = "1";
    //                        xlWorkSheet.Cells[_hang, ++_cot] = _subrow1[0];
    //                        xlWorkSheet.Cells[_hang, ++_cot] = _subrow1[1];
    //                        xlWorkSheet.Cells[_hang, ++_cot] = _subrow1[2];
    //                    }
    //                    if (!_subrow2[0].Equals(""))
    //                    {
    //                        _hangThem++;
    //                        _cot = _cot - 3;
    //                        xlWorkSheet.Cells[++_hang, _cot] = "2";
    //                        xlWorkSheet.Cells[_hang, ++_cot] = _subrow2[0];
    //                        xlWorkSheet.Cells[_hang, ++_cot] = _subrow2[1];
    //                        xlWorkSheet.Cells[_hang, ++_cot] = _subrow2[2];
    //                    }
    //                    if (!_subrow3[0].Equals(""))
    //                    {
    //                        _hangThem++;
    //                        _cot = _cot - 3;
    //                        xlWorkSheet.Cells[++_hang, _cot] = "3";
    //                        xlWorkSheet.Cells[_hang, ++_cot] = _subrow2[0];
    //                        xlWorkSheet.Cells[_hang, ++_cot] = _subrow2[1];
    //                        xlWorkSheet.Cells[_hang, ++_cot] = _subrow2[2];
    //                    }
    //                }
    //                if (_hangThem != 0) // tức là có gom hàng 
    //                {
    //                    xlWorkSheet.get_Range("A"+  (_hang - _hangThem) + ":A" + (_hang), Type.Missing).Merge(Type.Missing);
    //                    xlWorkSheet.get_Range("B" + (_hang - _hangThem) + ":B" + (_hang), Type.Missing).Merge(Type.Missing);
    //                    xlWorkSheet.get_Range("C" + (_hang - _hangThem) + ":C" + (_hang), Type.Missing).Merge(Type.Missing);
    //                    xlWorkSheet.get_Range("D" + (_hang - _hangThem) + ":D" + (_hang), Type.Missing).Merge(Type.Missing);
    //                    xlWorkSheet.get_Range("E" + (_hang - _hangThem) + ":E" + (_hang), Type.Missing).Merge(Type.Missing);
    //                    xlWorkSheet.get_Range("F" + (_hang - _hangThem) + ":F" + (_hang), Type.Missing).Merge(Type.Missing);
    //                    xlWorkSheet.get_Range("G" + (_hang - _hangThem) + ":G" + (_hang), Type.Missing).Merge(Type.Missing);
    //                    xlWorkSheet.get_Range("H" + (_hang - _hangThem) + ":H" + (_hang), Type.Missing).Merge(Type.Missing);
    //                    xlWorkSheet.get_Range("I" + (_hang - _hangThem) + ":I" + (_hang), Type.Missing).Merge(Type.Missing);
    //                    xlWorkSheet.get_Range("J" + (_hang - _hangThem) + ":J" + (_hang), Type.Missing).Merge(Type.Missing);
    //                    xlWorkSheet.get_Range("K" + (_hang - _hangThem) + ":K" + (_hang), Type.Missing).Merge(Type.Missing);
    //                    xlWorkSheet.get_Range("L" + (_hang - _hangThem) + ":L" + (_hang), Type.Missing).Merge(Type.Missing);
    //                    xlWorkSheet.get_Range("M" + (_hang - _hangThem) + ":M" + (_hang), Type.Missing).Merge(Type.Missing);
    //                    xlWorkSheet.get_Range("N" + (_hang - _hangThem) + ":N" + (_hang), Type.Missing).Merge(Type.Missing);
    //                    xlWorkSheet.get_Range("O" + (_hang - _hangThem) + ":O" + (_hang), Type.Missing).Merge(Type.Missing);
    //                    xlWorkSheet.get_Range("P" + (_hang - _hangThem) + ":P" + (_hang), Type.Missing).Merge(Type.Missing);
    //                    xlWorkSheet.get_Range("Q" + (_hang - _hangThem) + ":Q" + (_hang), Type.Missing).Merge(Type.Missing);
    //                    xlWorkSheet.get_Range("R" + (_hang - _hangThem) + ":R" + (_hang), Type.Missing).Merge(Type.Missing);
    //                    xlWorkSheet.get_Range("S" + (_hang - _hangThem) + ":S" + (_hang), Type.Missing).Merge(Type.Missing);
    //                    xlWorkSheet.get_Range("T" + (_hang - _hangThem) + ":T" + (_hang), Type.Missing).Merge(Type.Missing);
    //                    xlWorkSheet.get_Range("U" + (_hang - _hangThem) + ":U" + (_hang), Type.Missing).Merge(Type.Missing);
    //                    xlWorkSheet.get_Range("V" + (_hang - _hangThem) + ":V" + (_hang), Type.Missing).Merge(Type.Missing);
    //                }


    //        }

    //        // thông tin kết thúc
    //        xlWorkSheet.Cells[_hang+2, 2] = "Người lập biểu";
    //        xlWorkSheet.Cells[_hang + 2, 5] = tk.NoiGui + ", ngày " + DateTime.Now.Day + " tháng " + DateTime.Now.Month + " năm " + DateTime.Now.Year;
    //        xlWorkSheet.Cells[_hang + 3, 5] = "Giám Đốc";
    //        xlWorkSheet.Cells[_hang + 8, 2] = tk.NguoiLapBieu;
    //        xlWorkSheet.Cells[_hang + 8, 5] = tk.GiamDoc;

    //        ((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[_hang + 2, 2]).HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
    //        ((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[_hang + 3, 5]).HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
    //        ((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[_hang + 8, 2]).HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
    //        ((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[_hang + 8, 5]).HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
    //        ((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[_hang + 2, 2]).Font.Bold = true;
    //        ((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[_hang + 3, 5]).Font.Bold = true;
       

    //        xlWorkSheet.get_Range("A15:Z"+_hang, Type.Missing).VerticalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
    //        xlWorkSheet.get_Range("A13:Z" + _hang, Type.Missing).Borders.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous;
    //        xlWorkSheet.get_Range("A13:Z" + _hang, Type.Missing).Borders.Color = System.Drawing.ColorTranslator.ToOle(Color.Black);
    //        xlWorkSheet.get_Range("A13:Z" + _hang, Type.Missing).WrapText = true;

    //     // save lại
    //        xlWorkBook.SaveAs(fileName, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);

    //        // đóng lại
    //        xlWorkBook.Close(true, misValue, misValue);

    //        xlApp.Quit();
    //        releaseObject(xlWorkSheet);
    //        releaseObject(xlWorkBook);
    //        releaseObject(xlApp);



    //    }
    //    catch
    //    {

    //        throw;

    //    }
    
    //}

   //public void download(string path)
   // {
   //     Response.Clear();

   //     Response.AppendHeader("Content-Type", "application/vnd.ms-excel");
   //     Response.AddHeader("Content-Disposition", "attachement;filename=ThongKe_PhuLuc_1.xls");
   //     //Response.AddHeader("Attachment", "attachment;filename=ThongKe_PhuLuc_1.xls");
   //     Response.TransmitFile(path);
   //     Response.End();
   // }
    //private void releaseObject(object obj)
    //{
    //    try
    //    {
    //        System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
    //        obj = null;
    //    }
    //    catch (Exception ex)
    //    {
    //        obj = null;
    //        Response.Write("<script language='JavaScript'> alert('" + "Exception Occured while releasing object " + ex.ToString() + "'); </script>");
            
    //    }
    //    finally
    //    {
    //        GC.Collect();
    //    }
    //}

    protected void btnIn_Click(object sender, EventArgs e)
    {
        
           // string path = Server.MapPath("~/userfiles/vanban/ThongKe_PhuLuc_1.xls");
            // string path = Page_url.UploadPath+"ThongKe_PhuLuc_1.xls";
            //   //  HttpContext.Current.Request.MapPath("~/ThongKe_PhuLuc_1.xls");
        Response.Redirect("../TimKiem.aspx");
           // if (File.Exists(path))
            //    File.Delete(path);
            //Export_To_File(path);
        //    Response.Write("<script language='JavaScript'> alert('dasdsad'); </script>");
        //    try
        //    {
               
        //    }
          
        //catch
        //{

        //    throw;

        //}
        //   Response.Write("<script language='JavaScript'> alert('ss'); </script>");
         //  download(path);
      


    }
}